package vsqlbuilder.logic.sql;

import vsqlbuilder.Utils.typeofConnector;
import vsqlbuilder.Utils.typeofRestriction;

public class QueryRestriction {
	private String expresion;  //A expression can be a column or a function in a column...
	private typeofRestriction typeRestriction;
	private String Value1, Value2;
	private typeofConnector typeConnector;
	private int group;
	
	public QueryRestriction(){
		group=0; //by default the restriction is not inside ( ).
		expresion=null;
		typeRestriction=null;
		Value1=null;
		Value2=null;
		typeConnector=null;
	}
	
	public void setExpresion(String s){
		this.expresion=s;
	}

	public void setTypeRestriction(typeofRestriction tr){
		this.typeRestriction=tr;
	}
	
	public void setTypeConnector(typeofConnector tc){
		this.typeConnector=tc;
	}
	
	public void setValue1(String v){
		this.Value1=v;
	}

	public void setValue2(String v){
		this.Value2=v;
	}
	
	public void setGroup(int g){
		this.group=g;
	}
	
	public int getGroup(){
		return this.group;
	}
	
	public String getExpression(){
		return this.expresion;
	}

	public typeofRestriction getTypeRestriction(){
		return this.typeRestriction;
	}
	
	public String getStringTypeRestriction(){
		String value="";
		if(this.typeRestriction==typeofRestriction.EQUAL){
			value="=";
		}else if(this.typeRestriction==typeofRestriction.NOT_EQUAL){
			value="!=";
		}else if(this.typeRestriction==typeofRestriction.LESS){
			value="<";
		}else if(this.typeRestriction==typeofRestriction.MORE){
			value=">";
		}else if(this.typeRestriction==typeofRestriction.LESS_EQUAL){
			value="<=";
		}else if(this.typeRestriction==typeofRestriction.MORE_EQUAL){
			value=">=";
		}else if(this.typeRestriction==typeofRestriction.BETWEEN){
			value="BETWEEN";
		}else if(this.typeRestriction==typeofRestriction.NOT_BETWEEN){
			value="NOT BETWEEN";
		}else if(this.typeRestriction==typeofRestriction.LIKE){
			value="LIKE";
		}else if(this.typeRestriction==typeofRestriction.NOT_LIKE){
			value="NOT LIKE";
		}else if(this.typeRestriction==typeofRestriction.ILIKE){
			value="ILIKE";
		}else if(this.typeRestriction==typeofRestriction.NOT_ILIKE){
			value="NOT ILIKE";
		}else if(this.typeRestriction==typeofRestriction.IS_NULL){
			value="IS NULL";
		}else if(this.typeRestriction==typeofRestriction.IS_NOT_NULL){
			value="IS NOT NULL";
		}else if(this.typeRestriction==typeofRestriction.IN){
			value="IN";
		}else if(this.typeRestriction==typeofRestriction.NOT_IN){
			value="NOT IN";
		}
		return value;
	}
	
	public String getStringTypeConnector(){
		String value="";
		if(this.typeConnector.toString().equals("AND")){
			value="AND";
		}else if(this.typeConnector.toString().equals("OR")){
			value="OR";
		}
		return value;
	}
	
	public typeofConnector getTypeConnector(){
		return this.typeConnector;
	}
	
	public String getValue1(){
		return Value1;
	}

	public String getValue2(){
		return Value2;
	}
	
}
